package com.iwhalecloud.bss.kite.cucc.common.util;

import com.alibaba.fastjson.JSON;
import com.iwhalecloud.bss.kite.common.callclient.CallClient;
import com.iwhalecloud.bss.kite.common.util.TransactionIdUtils;
import com.ztesoft.bss.svcability.aggobj.SvcCont;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Pub {
	public static List getCrm20TableData(String table_name, Map WhereParams) throws Exception{
	    List resultList = new ArrayList();
        Map<String, Object> svcContStr = new HashMap<String, Object>();
        SvcCont svcCont = null;
        Map requetMap = new HashMap();
        svcContStr.put("ActionType", "QUERY");
        svcContStr.put("TableName", table_name);
        svcContStr.put("WhereParams", WhereParams);
        svcContStr.put("SetParams", WhereParams);
        requetMap.put("SvcContStr", JSON.toJSON(svcContStr).toString());
        requetMap.put("ReqTime", DateUtils.getDateTimeString(new Date(), "yyyyMMddHHmmss"));// 获取时间，20190717143611
        requetMap.put("TransactionID", TransactionIdUtils.getTransactionIdOrRandom());// 6003020033201701211536110000000001
        svcCont = CallClient.extCall("update.datadeal.crm", requetMap);
        if (svcCont != null && !"0000".equals(svcCont.getResultCode()) && !SvcCont.RESULT_CODE_SUCCESS.equals(svcCont.getResultCode())) {
            return resultList;
        }
        if (svcCont != null && svcCont.getResultObject().getData() != null) {
            Map<String, Object> map = svcCont.getResultObject().getData();
            if (map.containsKey("SvcCont") && ((Map<String, Object>) map.get("SvcCont")).containsKey("QueryResults")) {
                resultList = (List) ((Map<String, Object>) map.get("SvcCont")).get("QueryResults");
            }
            else {
                return resultList;
            }
        }
        else {
            return resultList;
        }
	    return resultList;
	}

}
